﻿<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Eventos
 *
 * @author marcelo.diaz
 */
class Eventos extends Controller{
    
    function Eventos(){
      parent::Controller("eventos");
      $this->load->model("Eventos_Model");
    }

	function index()
	{
      $email = "ALL";
      $this->email->from('conocepunta@gmail.com');
      $this->email->to('conocepunta@gmail.com');
      $this->email->subject('Event access');
      
      $data['page_title'] = "Recitales - Eventos culturales y sociales - Fiestas privadas y en boliches - Los mejores eventos en Punta Alta y la Zona";
      $data['meta_description'] = '<meta name="description" content="ConocePunta - Punta Alta, Buenos Aires, Argentina - Todos los eventos que ocurren en Punta Alta y la Zona - Fiestas, eventos culturales y sociales." />';      
      $output = $this->load->view('head_view', $data, true);
      
      $places = $this->Eventos_Model->_all();
      $navbar = $this->write_navbar();
      //iterate and parse places
      $output .= $navbar;
      $output .= "<div class='content centered'>";
      $output .= 	$this->write_custom_content($places);  
      $output .= 	$this->write_sidebar("recitales fiestas boliches discos eventos");
      $output .= "</div>";  
      //---------MAP---------
     // $output .= $this->write_map();              
      $output .= $this->load->view('foot_view', "", true);
      $this->output->set_output($output);
      //$this->email->message($email);
      //$this->email->send();
    }

    function name($place){
		$json = $this->Eventos_Model->get_place($place);
		header('Content-Type:application/json');
		echo json_encode($json);	  
    }   
	
    function all(){
      $json = $this->Eventos_Model->get_all();
      header('Content-Type:application/json');
      //!!!
      echo json_encode($json);		  
    }
	
    function nombre($name = false){
      if ($name){
        $email = "[".$name."]";
        $this->email->from('conocepunta@gmail.com');
        $this->email->to('conocepunta@gmail.com');
        $this->email->subject('Event access');
             
        $navbar = $this->write_navbar();
        $name_replaced = str_replace("-", " ", $name);        
        $data['page_title'] = $name_replaced." - Recitales - Eventos culturales y sociales - Fiestas privadas y en boliches - Los mejores eventos en Punta Alta y la Zona";
        $data['meta_description'] = '<meta name="description" content="'.$name_replaced.' - ConocePunta - Punta Alta, Buenos Aires, Argentina - Todos los eventos que ocurren en Punta Alta y la Zona - Fiestas, eventos culturales y sociales." />';        
        $output = $this->load->view('head_view', $data, true);        

        $banner_adsense = '<div class="lheader"><script type="text/javascript"><!--
                                      google_ad_client = "pub-2113662635661393";
                                      
                                      google_ad_slot = "4418063429";
                                      google_ad_width = 728;
                                      google_ad_height = 90;
                                      //-->
                                      </script>
                                      <script type="text/javascript"
                                      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                                      </script></div>';
        
        $output .= $navbar.
                   "<div class='content slim-content centered' style='height:120px'>".
        				$banner_adsense.
                   "</div>";        
        
        $content = "";
        //$place = $this->Eventos_Model->_place(strtolower($name));
		$place = $this->Eventos_Model->get_place($name);
        if (!$place){
          $places = $this->Eventos_Model->_all();
          //iterate and parse places
	      $content .= "<div class='content centered'>".
	 	      			"<p class='ui-state-highlight' style='width:50%; padding:10px; text-align:center;'>No hemos podido encontrar <strong>$name</strong>.</p>";
	      $content .= 	$this->write_custom_content($places);  
	      $content .= 	$this->write_sidebar("recitales fiestas boliches discos eventos");
	      $content .= "</div>";                                  
          $email .= "NOT FOUND";                  
        } else{        	
          //parse place          
        	$content .= "<div class='content slim-content centered'>".
        					$this->write_specific_item($place).
        				"</div>";
        }        
		$output .= $content; 
        
        $output .= $this->load->view('foot_view', "", true);        
        $this->output->set_output($output);
        //$this->email->message($email);
        //$this->email->send();

      }else{
        $this->index();
      }
    } 
    
    function write_custom_content($places){
    	$content = "<div id='events' class='lheader'>";
    	$counter = 1;
    
    	foreach ($places as $place){    		
    		//----------------------------------------
    		$date = date("M D j, G:i",strtotime($place['fecha']))."HS";
    		
    		$evt_date = new DateTime($place['fecha']);
    		$now 	  = new DateTime("now");
    		$interval = $now->diff($evt_date);
    		$evt_tape = ($interval->invert == 1)?"":"<div class='tape'><div class='triangle triangle_left_r'></div><span class='date new inline'>".$date."</span></div>";
    		//$evt_tape = "<div class='tape'><div class='triangle triangle_left_r'></div><span class='date new inline'>".$date."</span></div>";
    		//----------------------------------------
    		if(($counter % 15) != 0){
    			$face_like = '<span>
    			<iframe src="http://www.facebook.com/plugins/like.php?href='.base_url().$this->get_controller_name().'/nombre/'.$place['name'].'&amp;layout=button_count&amp;show-faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;locale=es_LA" frameborder="0" scrolling="no" style="vertical-align: middle; border: medium none; overflow: hidden; width: 100px; height: 21px;" allowtransparency="true"></iframe>
    			</span>';
    			$name_replaced = str_replace("-", " ", $place['name']);
    				
    			//$image = ($place->img == "") ? "<figure><img title='".$name_replaced."' alt='".$name_replaced."' src='".base_url().$place->icon."'></figure>" : "<figure><img title='".$name_replaced."' alt='".$name_replaced."' src='".$place->img."'></figure>";
    			$image = "<figure><img title='".$name_replaced."' alt='".$name_replaced."' src='".$place['img']."'></figure>";
    			$content .= "<article class='inline box post' title='".$name_replaced."'>".
      					$evt_tape.
    					"<div class='screenshot vintage'>".
    					$image.
    					"<p class='hover'>".
    					"<a class='hoverButton inline' href='".base_url().$this->get_controller_name()."/nombre/".$place['name']."'>Mas</a>".
    					//"<a class='hoverButton inline geoButton' id='".$place['name']."' onclick='locate(\"".$this->get_controller_name()."\", this.id);'>Mapa</a>".
    					"</p>".
    					"</div>".
    					"<div class='figcaption'>".
    					//"<p>".str_pad(substr($name_replaced,0,20),23,"...")."</p>".
    			"<p>$name_replaced</p>".
    			"</div>".
    			"<div class='fb_like'>$face_like</div>".
    			"</article>";
    		}else{
    		if(($counter % 15) == 0){
    				//post Google Ad
    				$content .= "<article class='inline box post'>".
    					"<div class='screenshot vintage'>".
    					"<figure>".
    					"<script type='text/javascript'><!--
    					google_ad_client = 'ca-pub-2113662635661393';
    					/* custom_content */
    					google_ad_slot = '7944803694';
    					google_ad_width = 170;
    					google_ad_height = 200;
    					//-->
    					</script>
    					<script type='text/javascript'
    					src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>
    					</script>".
    					"</figure>".
    					"<p class='hover'>".
    					"</p>".
    					"</div>".
    					"</article>";
    				}else{
    					//post eco banner
    					$content .= "<article class='inline box post'>".
    					"<div class='screenshot vintage'>".
    					"<figure>".
    					"<img src='http://www.greenpeace.org/argentina/Global/argentina/graphics/probono/artico/250x250.jpg' width='140' height='210' border='0' />".
    					"</figure>".
    					"<p class='hover'>".
    					"<a class='hoverButton inline' target='_blank' href='http://www.greenpeace.org.ar/cyberacciones/index.php?cyberaccion=5122&referer=baners_webprobono_artico'>M&aacute;s</a>".
    					"</p>".
    					"</div>".
    					"<div class='figcaption'>".
    					"<p>Campa&ntilde;a Greenpeace</p>".
    					"</div>".
    					"</article>";
    					}
    					}
    					$counter ++;
    					}
    					$content .= "</div>";
    					return $content;
    	}

    	function write_specific_item($marker){
    		$content = "";
    		$marker_name = str_replace("-", " ", $marker['name']);
    		$url  = "www.conocepunta.com.ar/".$this->get_controller_name()."/nombre/".$marker['name'];
    	
    		$date = ($marker["fecha"] != "")?date("M D j - Y, G:i",strtotime($marker["fecha"]))."HS: ": "";
    		//social widgets---------------------
    		$fb   = "<div class='fb_like'><iframe src='http://www.facebook.com/plugins/like.php?href=".$url."&amp;layout=button_count&amp;show-faces=false&amp;width=100&amp;action=like&amp;colorscheme=light&amp;locale=es_LA' frameborder='0' scrolling='no' style='vertical-align: middle; border: medium none; overflow: hidden; width: 100px; height: 21px;' allowtransparency='true'></iframe></div>";
    		$addthis = '<div class="addthis_toolbox fb_like">'.
    				'<div class="hover_effect">'.
    				'<div style="display:inline-block"><a class="addthis_button_twitter"'.
    				'addthis:url="http://'.$url.'"'.
    				'addthis:title="'.$date.$marker_name.' en '.$marker["address"].' #'.str_replace(" ","", $marker["city"]).' @conocepunta">&nbsp;</a></div>'.
    				'<div style="display:inline-block"><a class="addthis_button_google"'.
    				'addthis:url="http://'.$url.'"'.
    				'addthis:title="'.$marker_name.': '.$marker["address"].' @conocepunta">&nbsp;</a></div>'.
    				'<div style="display:inline-block"><a class="addthis_button_expanded">&nbsp;&nbsp;Mas</a></div>'.
    				'<div style="clear:both; float:none;"></div>'.
    				'</div>'.
    				'</div>';
    		//$gplusbutton = '<g:plusone size="small" href="http://'.$url.'"></g:plusone>';
    			
    		$social = "<div>".$fb.$addthis."</div>";
    		//--------------------------------
    	
    		//---------------static map
    		$image = "<figure><img alt='".$marker_name."' class='lheader' src='http://maps.google.com/staticmap?center=".$marker['lat'].",".$marker['lng']."&zoom=15&size=225x225&maptype=satellite&&markers=".$marker['lat'].",".$marker['lng']."&key=ABQIAAAALyKwFZzMQBTWU3CUmBrN7RTvufBQ4WA-npmjEqhq0GDcUkCFMRTabPeW_m0vIN3Bghd4m7Mv_m-mOQ'></figure>";
    		//-------------------------
    	
    		$desc = "<p>".$marker['description']."</p>";
    		$screen = "<div class='vintage lheader' style='margin-bottom:7px'>".
    				$image.
    				"</div>".
    				"<div class='figcaption'>".
    		"<p>".$marker['address']."</p>".
    		"<p class='place'>".$marker['city']."</p>".
    		"</div>".
    		$social;
    		//----------------------------------------------------------------------
    		//loading related data
    		$related = "<ul>";
    		foreach ($marker['related'] as $k => $rel){
    			$clean_name = str_replace("-", " ", $rel['name']);
    			$related .= "<li class='box mini-post figcaption'>
    			<figure><img class='small' title='".$clean_name."' alt='".$clean_name."' src='".$rel['img']."'></figure>
    			<a href='".base_url().$this->category_string($rel['marker_cat'])."/nombre/".$rel['name']."' target='_new'>".$clean_name."</a>
    			</li>";
    		}
    		$related .= "</ul>";
    	
    		$content =  "<div class='brief box post'>".
    				//title
    		"<div>".
    		"<h1>".$marker_name."</h1>".
    		"<p class='place'>$date</p>".
    		"</div>".
    		"<p class='separator'></p>".
    		//------
    		"<article id='".$marker['name']."' class='inline box post lheader'>".
    		$screen.
    		"</article>".
    		"<article class='inline' style='padding-left: 20px; max-width: 500px;'>".
    		"<div>".
    		$desc.
    		//$social.
    		"</div>".
    		"</article>".
    		//"<p class='separator'></p>".
    		"<article class='inline figcaption' style='width:100%'>".
    		"<p class='separator'></p>".
    		"<p class='place' style='text-align:left; padding-bottom:10px'>Entradas relacionadas...</p>".
    		$related.
    		"</article>".
    		"</div>";
    		return $content;
    	}    	
}
?>
